package com.junzhiit.nengji.cms.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.cms.service.OrdersRefundService;
import com.junzhiit.nengji.cms.web.vo.DataTablesParamVO;
import com.junzhiit.nengji.cms.web.vo.OrdersRefundVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("orders/refund")
public class OrdersRefundController {
	
	@Autowired
	private OrdersRefundService ordersRefundService;

	@ApiOperation(value = "获取所有退款记录")
	@RequestMapping(method = RequestMethod.GET)
	public Map<String, Object> findAll(DataTablesParamVO dtp, OrdersRefundVO ordersRefundVO) {
		return ordersRefundService.findAll(dtp, ordersRefundVO);
	}
	
	@ApiOperation(value = "更新状态")
	@RequestMapping(value = "/update", method = RequestMethod.PUT)
	public ResultVO update(OrdersRefundVO ordersRefundVO) {
		return ordersRefundService.update(ordersRefundVO);
	}
	
	@ApiOperation(value = "同意商家点击的退款")
	@RequestMapping(value = "/agree", method = RequestMethod.PUT)
	public ResultVO refund(String id) {
		return ordersRefundService.refund(id);
	}
	
	@ApiOperation("查询退款申请条数")
	@RequestMapping(value = "/count", method = RequestMethod.GET)
	public ResultVO getApplyTotal(String sessionId) {
		AssertUtil.notBlank(sessionId, "sessionId is required.");
		return ordersRefundService.getApplyTotal(sessionId);
	}
}
